home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / lisp / guile-ii.src / guile-ii / guile-src / slib / t3.init < prev    next >
Encoding:
Text File  |  1994-11-27  |  12.4 KB  |  426 lines

  1. ;"t3.init" Initialization file for SLIB for T3.1.    -*-scheme-*-
  2. ;Copyright (C) 1991, 1992 David Carlton & Stephen Bevan
  3. ;Copyright 1993 F. Javier Thayer.
  4. ;Copyright (C) 1991, 1992, 1993 Aubrey Jaffer.
  5. ;
  6. ;Permission to copy this software, to redistribute it, and to use it
  7. ;for any purpose is granted, subject to the following restrictions and
  8. ;understandings.
  9. ;
  10. ;1.  Any copy made of this software must include this copyright notice
  11. ;in full.
  12. ;
  13. ;2.  I have made no warrantee or representation that the operation of
  14. ;this software will be error-free, and I am under no obligation to
  15. ;provide any services, by way of maintenance, update, or otherwise.
  16. ;
  17. ;3.  In conjunction with products arising from the use of this
  18. ;material, there shall be no use of my name in any advertising,
  19. ;promotional, or sales literature without prior written consent in
  20. ;each case.
  21.  
  22. ;;; File has T syntax, and should be compiled in standard-env.
  23. ;;; Compiled file has .so suffix.
  24. ;;; File (or compiled version) should be loaded into scheme-env.
  25.  
  26. ;;; This is provided with ABSOLUTELY NO GUARANTEE.
  27. (herald t3)
  28.  
  29. (define (software-type) 'UNIX)
  30.  
  31. (define (scheme-implementation-type) 'T)
  32.  
  33. (define (scheme-implementation-version) "3.1")
  34.  
  35. ;;; (implementation-vicinity) should be defined to be the pathname of
  36. ;;; the directory where any auxillary files to your Scheme
  37. ;;; implementation reside. It is settable.
  38.  
  39. (define implementation-vicinity
  40.   (make-simple-switch 'implementation-vicinity
  41.               (lambda (x) (or (string? x) (false? x)))
  42.               '#f))
  43. (set (implementation-vicinity) "/usr/local/lib/tsystem/")
  44.  
  45. ;;; (library-vicinity) should be defined to be the pathname of the
  46. ;;; directory where files of Scheme library functions reside. It is settable.
  47.  
  48. (define library-vicinity
  49.   (make-simple-switch 'library-vicinity
  50.               (lambda (x) (or (string? x) (false? x)))
  51.               '#f))
  52. (set (library-vicinity) "/usr/local/lib/slib/")
  53. ;;Obviously put your value here.
  54.  
  55. ;;; *FEATURES* should be set to a list of symbols describing features
  56. ;;; of this implementation.  See Template.scm for the list of feature
  57. ;;; names.
  58.  
  59. (define *features*
  60.       '(
  61.     source                ;can load scheme source files
  62.                     ;(slib:load-source "filename")
  63.     compiled            ;can load compiled files
  64.                     ;(slib:load-compiled "filename")
  65.     rev3-report
  66.     rev4-optional-procedures
  67.     rev3-procedures
  68.     rev2-procedures
  69.     multiarg/and-
  70.     multiarg-apply
  71.     rationalize
  72.     object-hash
  73.     delay
  74.     i/o-redirection
  75.     char-ready?
  76.     with-file
  77.     transcript
  78.     full-continuation
  79.     pretty-print
  80.     format
  81.     trace                ;has macros: TRACE and UNTRACE
  82.     program-arguments
  83.     ))
  84.  
  85. (define substring
  86.   (let ((primitive-substring (*value standard-env 'substring)))
  87.     (lambda (string start end)
  88.       (primitive-substring string start (max 0 (- end 1))))))
  89.  
  90. ; Modify substring as T's substring takes (start,count) instead of
  91. ; (start,end)
  92.  
  93. (set (syntax-table-entry (env-syntax-table scheme-env) 'require) '#f)
  94.  
  95. ; Turn off the macro REQUIRE so that it can be rebound as a function
  96. ; later.
  97.  
  98. ; extend <, >, <= and >= so that they take more than two arguments.
  99.  
  100. (define <
  101.   (let ((primitive< (*value standard-env '<)))
  102.     (labels ((v (lambda (a b . rest)
  103.           (if (null? rest)
  104.               (primitive< a b)
  105.               (and (primitive< a b)
  106.                (apply v b (car rest) (cdr rest)))))))
  107.         v)))
  108.  
  109. (define >
  110.   (let ((primitive> (*value standard-env '>)))
  111.     (labels ((v (lambda (a b . rest)
  112.           (if (null? rest)
  113.               (primitive> a b)
  114.               (and (primitive> a b)
  115.                (apply v b (car rest) (cdr rest)))))))
  116.         v)))
  117.  
  118. (define <=
  119.   (let ((primitive<= (*value standard-env '<=)))
  120.     (labels ((v (lambda (a b . rest)
  121.           (if (null? rest)
  122.               (primitive<= a b)
  123.               (and (primitive<= a b)
  124.                (apply v b (car rest) (cdr rest)))))))
  125.         v)))
  126.  
  127. (define >=
  128.   (let ((primitive>= (*value standard-env '>=)))
  129.     (labels ((v (lambda (a b . rest)
  130.           (if (null? rest)
  131.               (primitive>= a b)
  132.               (and (primitive>= a b)
  133.                (apply v b (car rest) (cdr rest)))))))
  134.         v)))
  135.  
  136. (define =
  137.   (let ((primitive= (*value standard-env '=)))
  138.     (labels ((v (lambda (a b . rest)
  139.           (if (null? rest)
  140.               (primitive= a b)
  141.               (and (primitive= a b)
  142.                (apply v b (car rest) (cdr rest)))))))
  143.         v)))
  144.  
  145. (define gcd
  146.   (let ((prim (*value standard-env 'gcd)))
  147.     (labels ((v (lambda x
  148.           (cond ((null? x) 0)
  149.             ((= (length x) 1) (car x))
  150.             ('#t (prim (car x) (apply v (cdr x))))))))
  151.         v)))
  152.  
  153. (define list? (*value standard-env 'proper-list?))
  154.  
  155. (define program-arguments command-line)
  156.  
  157. ;;; (OUTPUT-PORT-WIDTH <port>)
  158. (define output-port-width
  159.   (lambda x
  160.     (if (null? x) (line-length (standard-input))
  161.     (line-length (car x)))))
  162.  
  163. ;;; (OUTPUT-PORT-HEIGHT <port>)
  164. (define (output-port-height . arg) 24)
  165.  
  166. ;;; (CURRENT-ERROR-PORT)
  167. (define current-error-port
  168.   (let ((port (current-output-port)))
  169.     (lambda () port)))
  170.  
  171. ;;; (TMPNAM) makes a temporary file name.
  172. (define tmpnam
  173.   (let ((cntr 100))
  174.     (lambda () (set! cntr (+ 1 cntr))
  175.         (let ((tmp (string-append "slib_" (number->string cntr))))
  176.           (if (file-exists? tmp) (tmpnam) tmp)))))
  177.  
  178. (define delete-file file-delete)
  179.  
  180. ;;; CHAR-CODE-LIMIT is one greater than the largest integer which can
  181. ;;; be returned by CHAR->INTEGER.
  182. (define char-code-limit 256)
  183.  
  184. ;;; MOST-POSITIVE-FIXNUM is used in modular.scm
  185. ;;; T already has it.
  186.  
  187. ;;; Return argument
  188. (define (identity x) x)
  189.  
  190. ;;; If your implementation provides eval, SLIB:EVAL is single argument
  191. ;;; eval using the top-level (user) environment.
  192. (define (slib:eval form) (eval form scheme-env))
  193.  
  194. ;;; If your implementation provides R4RS macros:
  195. ;(define macro:eval slib:eval)
  196. ;(define macro:load load)
  197.  
  198. (define *defmacros*
  199.   (list (cons 'defmacro
  200.           (lambda (name parms . body)
  201.         `(set! *defmacros* (cons (cons ',name (lambda ,parms ,@body))
  202.                       *defmacros*))))))
  203. (define (defmacro? m) (and (assq m *defmacros*) #t))
  204.  
  205. (define (macroexpand-1 e)
  206.   (if (pair? e) (let ((a (car e)))
  207.           (cond ((symbol? a) (set! a (assq a *defmacros*))
  208.                      (if a (apply (cdr a) (cdr e)) e))
  209.             (else e)))
  210.       e))
  211.  
  212. (define (macroexpand e)
  213.   (if (pair? e) (let ((a (car e)))
  214.           (cond ((symbol? a)
  215.              (set! a (assq a *defmacros*))
  216.              (if a (macroexpand (apply (cdr a) (cdr e))) e))
  217.             (else e)))
  218.       e))
  219.  
  220. (define gentemp
  221.   (let ((*gensym-counter* -1))
  222.     (lambda ()
  223.       (set! *gensym-counter* (+ *gensym-counter* 1))
  224.       (string->symbol
  225.        (string-append "slib:G" (number->string *gensym-counter*))))))
  226.  
  227. (define base:eval slib:eval)
  228. (define (defmacro:eval x) (base:eval (defmacro:expand* x)))
  229. (define (defmacro:expand* x)
  230.   (require 'defmacroexpand) (apply defmacro:expand* x '()))
  231.  
  232. (define (defmacro:load <pathname>)
  233.   (slib:eval-load <pathname> defmacro:eval))
  234.  
  235. (define (slib:eval-load <pathname> evl)
  236.   (if (not (file-exists? <pathname>))
  237.       (set! <pathname> (string-append <pathname> (scheme-file-suffix))))
  238.   (call-with-input-file <pathname>
  239.     (lambda (port)
  240.       (let ((old-load-pathname *load-pathname*))
  241.     (set! *load-pathname* <pathname>)
  242.     (do ((o (read port) (read port)))
  243.         ((eof-object? o))
  244.       (evl o))
  245.     (set! *load-pathname* old-load-pathname)))))
  246.  
  247. ;;; define an error procedure for the library
  248. (define slib:error error)
  249.  
  250. ;;; define these as appropriate for your system.
  251. (define slib:tab #\tab)
  252. (define slib:form-feed #\form)
  253.  
  254. ;;; Define these if your implementation's syntax can support it and if
  255. ;;; they are not already defined.
  256.  
  257. ;(define (1+ n) (+ n 1))
  258. (define (1- n) (+ n -1))
  259. ;(define (-1+ n) (+ n -1))
  260.  
  261. (define program-vicinity
  262.   (make-simple-switch 'program-vicinity
  263.               (lambda (x) (or (string? x) (false? x)))
  264.               '#f))
  265.  
  266. (define in-vicinity string-append)
  267.  
  268. ;;; Define SLIB:EXIT to be the implementation procedure to exit or
  269. ;;; return if exitting not supported.
  270. (define slib:exit (lambda args (exit))
  271.  
  272. (define (string . args) (apply string-append (map char->string args)))
  273.  
  274. (define make-string
  275.   (let ((t:make-string (*value standard-env 'make-string)))
  276.     (lambda (a . b)
  277.       (let ((str (t:make-string a)))
  278.     (if b (map-string! (lambda (x) (ignore x) (car b)) str) str)))))
  279.  
  280. (define (string>? a b)
  281.   (labels ((aux
  282.         (lambda (n a b)
  283.           ;;start off with n<=(string-length b) and n<=(string-length a)
  284.           ;;a,b coincide for chars <n
  285.           (cond ((= (string-length a) n) (< n (string-length b)))
  286.                     ;;now (< n (string-length a))
  287.             ((= (string-length b) n) '#f)
  288.                     ;;now (< n (string-length a))
  289.             ((char=? (nthchar a n) (nthchar b n) ) (aux (+ 1 n) a b))
  290.             ('#t (char<? (nthchar b n) (nthchar a n)))))))
  291.     (aux 0 a b)))
  292.  
  293. (define (string<? a b) (string>? b a))
  294. (define (string<=? a b) (not (string>? a b)))
  295. (define (string>=? a b) (not (string<? a b)))
  296.  
  297. (define (string-ci<? a b)
  298.   (string<? (string-upcase a) (string-upcase b)))
  299.  
  300. (define (string-ci>? a b)
  301.   (string>? (string-upcase a) (string-upcase b)))
  302.  
  303. (define (string-ci<=? a b)
  304.   (string<=? (string-upcase a) (string-upcase b)))
  305.  
  306. (define (string-ci>=? a b)
  307.   (string>=? (string-upcase a) (string-upcase b)))
  308.  
  309. ;;; FORCE-OUTPUT flushes any pending output on optional arg output port
  310. ;;; use this definition if your system doesn't have such a procedure.
  311. ;;; T already has it, but requires 1 argument.
  312.  
  313. (define force-output
  314.   (let ((t:force-output (*value standard-env 'force-output)))
  315.     (lambda x
  316.       (if x
  317.       (t:force-output (car x))
  318.       (t:force-output (current-output-port))))))
  319.  
  320. ;;; CALL-WITH-INPUT-STRING and CALL-WITH-OUTPUT-STRING are the string
  321. ;;; port versions of CALL-WITH-*PUT-FILE.
  322. (define (call-with-output-string proc)
  323.   (with-output-to-string var (proc var)))
  324.  
  325. (define (call-with-input-string string proc)
  326.   (with-input-from-string (variable string) (proc variable)))
  327.  
  328. (define (string->number s . x)
  329.   (let ((base (if x (car x) 10))
  330.     (s (string-upcase s)))
  331.     (or (mem? = base '(8 10 16))
  332.     (error (format (current-error-port) "Bad radix ~A" base)))
  333.     (if (= (string-length s) 0) '()
  334.     (let ((char->number
  335.            (lambda (ch)
  336.          (cdr (ass char=? ch
  337.                '((#\0 . 0)
  338.                  (#\1 . 1) (#\2 . 2) (#\3 . 3) (#\4 . 4)
  339.                  (#\5 . 5) (#\6 . 6) (#\7 . 7) (#\8 . 8)
  340.                  (#\9 . 9) (#\A . 10) (#\B . 11) (#\C . 12)
  341.                  (#\D . 13) (#\E . 14) (#\F . 15)))))))
  342.       (catch not-num
  343.          (iterate loop ((pos (- (string-length s) 1))
  344.                 (power 1) (accum 0))
  345.               (if (< pos 0) accum
  346.                   (let ((num (char->number (string-ref s pos))))
  347.                 (or num (not-num '()))
  348.                 (or  (< num base) (not-num '()))
  349.                 (loop (- pos 1)
  350.                       (* power base)
  351.                       (+ accum (*  num power)))))))))))
  352.  
  353. (define (number->string n . x)
  354.   (let ((rad (if (car x) (car x) 10)))
  355.     (format nil
  356.         (case rad
  357.           ((8) "~O")
  358.           ((10) "~D")
  359.           ((16) "~X")
  360.           (else (error (format (current-error-port)
  361.                    "Bad radix ~A" (car x)))))
  362.         n)))
  363.  
  364. (define (inexact? f)
  365.   (float? f))
  366.  
  367. (define (exact? f)
  368.   (not (inexact? f)))
  369.  
  370. (define exact->inexact ->float)
  371.  
  372. (define peek-char
  373.   (let ((t:peek-char (*value standard-env 'peek-char)))
  374.     (lambda p
  375.       (let ((port (if p (car p) (current-input-port))))
  376.     (t:peek-char port)))))
  377.  
  378. ;;;(set ((*value scheme-env 'standard-early-binding-env) 'load) '#f)
  379. ;;;(set ((*value scheme-env 'standard-early-binding-env) 'substring) '#f)
  380. (set ((*value scheme-env 'standard-early-binding-env) 'less?) '#f)
  381. (set ((*value scheme-env 'standard-early-binding-env) 'greater?) '#f)
  382. (set ((*value scheme-env 'standard-early-binding-env) 'not-less?) '#f)
  383. (set ((*value scheme-env 'standard-early-binding-env) 'not-greater?) '#f)
  384. (set ((*value scheme-env 'standard-early-binding-env) 'number-equal?) '#f)
  385. (set ((*value scheme-internal-env 'standard-early-binding-env) 'list?) '#f)
  386.  
  387. (set ((*value t-implementation-env 'SOURCE-FILE-EXTENSION)) 'scm)
  388.  
  389. ;;; Here for backward compatability
  390. (define (scheme-file-suffix) "")
  391.  
  392. (define load
  393.   (let ((t:load (*value standard-env 'load)))
  394.     (lambda (filespec . x)
  395.       (apply t:load (->filename filespec) x))))
  396.  
  397. ;;; (SLIB:LOAD-SOURCE "foo") should load "foo.scm" or with whatever
  398. ;;; suffix all the module files in SLIB have.  See feature 'SOURCE.
  399.  
  400. (define slib:load-source load)
  401.  
  402. ;;; (SLIB:LOAD-COMPILED "foo") should load the file that was produced
  403. ;;; by compiling "foo.scm" if this implementation can compile files.
  404. ;;; See feature 'COMPILED.
  405.  
  406. (define slib:load-compiled load)
  407.  
  408. ;;; At this point SLIB:LOAD must be able to load SLIB files.
  409.  
  410. (define slib:load slib:load-source)
  411.  
  412. (slib:load (in-vicinity (library-vicinity) "require") scheme-env)
  413.  
  414. ;;;(define scheme-read-table
  415. ;;;  (make-read-table standard-read-table 'modified-read-table))
  416. ;;;
  417. ;;;(set (read-table-entry scheme-read-table '#\#)
  418. ;;;     (lambda  (p ch rtable)
  419. ;;;       (ignore ch) (ignore rtable)
  420. ;;;       ((*value scheme-env 'string->number)
  421. ;;;    (symbol->string (read-refusing-eof p)) 16)))
  422. ;;;
  423. ;;;(set (port-read-table (standard-input)) scheme-read-table)
  424.  
  425. ; eof
  426.